package aop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;

public class LogHandler implements InvocationHandler{

	private Object target;
	
	public LogHandler(Object target)
	{
		this.target = target;
	}
	
	//实现拦截逻辑
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		
		MyLogger logger = new MyLogger();
		logger.log("Method: "+method.getName()+"; args: "+Arrays.toString(args));
		
		//勿忘调用Target的方法（即 被拦截方法）
		Object result = method.invoke(target, args);
		
		logger.log("Method: "+method.getName()+" ends.");
		
		//注意！！
		return result;
	}

}
